import {setData,getData,userInfoObj,getStorage,removeList} from '../../common/storage.js'

export default {
	namespaced:true,
	state:() => ({
			userInfo:getData('snowInfo') || userInfoObj,
			// #ifdef MP-WEIXIN
			downloadArr:getStorage('downloadList') || [],
			// #endif
			
			likeArr:getStorage('likeList') || []
	}),
	mutations:{
		// 给userInfo对象赋值
		setUserInfo(state,obj){
			state.userInfo = obj
		},
		// 修改昵称
		editNickName(state,name){
			state.userInfo.name = name
			// 数据持久化
			setData('snowInfo',JSON.stringify(state.userInfo))
		},
		// 修改头像
		editImage(state,imgURL){
			state.userInfo.avatar = imgURL
			// 数据持久化
			setData('snowInfo',JSON.stringify(state.userInfo))
		},
		// 增加Snow分
		addSnowNum(state,num){
			state.userInfo.snowNum += num
			// 数据持久化
			setData('snowInfo',JSON.stringify(state.userInfo))
		},
		// 修改背景图
		editBgImg(state,url){
			state.userInfo.bgImgUrl= url
			// 数据持久化
			setData('snowInfo',JSON.stringify(state.userInfo))
		},
		// 记录下载的壁纸
		downloadList(state,obj){
			state.downloadArr.push(obj)
			// 数据持久化yy
			setData('downloadList',state.downloadArr)
		},
		// 清空已下载的壁纸
		clearImage(state,arr){
			state.downloadArr = arr
			removeList('downloadList')
		},
		// 记录收藏的壁纸
		likeList(state,obj){
			state.likeArr.push(obj)
			console.log(state.likeArr);
			setData('likeList',state.likeArr)
		},
		// 清空收藏过的壁纸
		clearLike(state,arr){
			state.likeArr = arr
			removeList('likeList')
		}
	},
}